package com.mianshi.java01.entity;

import java.util.Map;

// 计价器类
public class Cashier {
    private boolean hasFullDiscount;

    public Cashier(boolean hasFullDiscount) {
        this.hasFullDiscount = hasFullDiscount;
    }

    public double calculateTotal(Customer customer) {
        double total = 0;
        for (Map.Entry<Fruit, Integer> entry : customer.getShoppingCart().entrySet()) {
            Fruit fruit = entry.getKey();
            int quantity = entry.getValue();
            total += fruit.getDiscountedPrice() * quantity;
        }

        // 满减优惠
        if (hasFullDiscount && total >= 100) {
            total = total - Math.floor( total / 100) * 10;
        }

        return total;
    }
}
